<style>
    .ueditor{
        line-height: 20px;
        z-index: 2;
        position: relative;
    }
</style>
<template>
    <div class="ueditor">
        <script :id="eid" type="text/plain"></script>
    </div>
</template>

<script>
    /* eslint-disable arrow-spacing,key-spacing,space-before-function-paren,space-before-blocks,keyword-spacing,no-console,no-undef */
    export default {
        name: 'file-upload',
        data () {
            return {
                editor: null
            };
        },
        props: {
            eid: {
                type: String,
                default: 'editor'
            },
            defaultMsg: {
                type: String
            },
            config: {
                type: Object,
                default:()=>{
                    return {
                        initialFrameHeight:500
                    };
                }
            }
        },
        watch:{
            $route: function () {
                const _this = this;
                _this.editor.destroy();
            }
//            ,defaultMsg(val){
//                const _this = this;
//                if(_this.editor){
//                    _this.editor.setContent(val);
//                }
//            }
        },
        methods: {
            getContent(){
                const _this = this;
                return _this.editor.getContent();
            },
            setContent(defaultMsg){
                const _this = this;
                if(_this.editor){
                    _this.editor.setContent(defaultMsg);
                }
            }
        },
        mounted () {
            const _this = this;
            // if(_this.editor){

            // }
            setTimeout(function () {
                _this.editor = UE.getEditor(_this.eid, _this.config); // 初始化UE
                _this.editor.addListener('ready', function () {
                    _this.editor.setContent(_this.defaultMsg); // 确保UE加载完成后，放入内容。
                });
                _this.editor.addListener('contentChange', function() {
                    _this.$emit('contentChange', _this.editor.getContent());
                });
            });
        },
        destroyed() {
            console.log('销毁编辑器');
            const _this = this;
            _this.editor.destroy();
        }
    };
</script>
